package com.zhoug.router;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

import com.alibaba.android.arouter.facade.Postcard;

import java.io.Serializable;
import java.util.ArrayList;

import androidx.annotation.Nullable;

/**
 * 封装Postcard
 *
 * @Author HK-LJJ
 * @Date 2020/3/19
 * @Description
 */
public final class MyPostcard {
    private Postcard postcard;

    MyPostcard(Postcard postcard) {
        this.postcard = postcard;
    }

    /**
     * 参数 对应{@link Intent#getExtras()}
     *
     * @param args
     * @return
     */
    public MyPostcard with(Bundle args) {
        postcard.with(args);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withString(@Nullable String key, @Nullable String value) {
        postcard.withString(key, value);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withInt(@Nullable String key, int value) {
        postcard.withInt(key, value);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withSerializable(@Nullable String key, @Nullable Serializable value) {
        postcard.withSerializable(key, value);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withFlags(int flags) {
        postcard.withFlags(flags);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withBundle(@Nullable String key, @Nullable Bundle value) {
        postcard.withBundle(key, value);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withLong(@Nullable String key, long value) {
        postcard.withLong(key, value);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withFloat(@Nullable String key, float value) {
        postcard.withFloat(key, value);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withDouble(@Nullable String key, double value) {
        postcard.withDouble(key, value);
        return this;
    }

    /**
     * 参数
     *
     * @return
     */
    public MyPostcard withStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
        postcard.withStringArrayList(key, value);
        return this;
    }

    public MyPostcard withCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value) {
        postcard.withCharSequenceArrayList(key, value);
        return this;
    }

    public MyPostcard withBoolean(@Nullable String key, boolean value) {
        postcard.withBoolean(key, value);
        return this;
    }

    public MyPostcard withChar(@Nullable String key, char value) {
        postcard.withChar(key, value);
        return this;
    }

    public MyPostcard withByte(@Nullable String key, byte value) {
        postcard.withByte(key, value);
        return this;
    }

    public MyPostcard withShort(@Nullable String key, short value) {
        postcard.withShort(key, value);
        return this;
    }

    public MyPostcard withIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
        postcard.withIntegerArrayList(key, value);
        return this;
    }

    public MyPostcard withParcelable(@Nullable String key, @Nullable Parcelable value) {
        postcard.withParcelable(key, value);
        return this;
    }

    public MyPostcard withParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value) {
        postcard.withParcelableArrayList(key, value);
        return this;
    }

    /**
     * 动画
     *
     * @param enterAnim 进入动画
     * @param exitAnim  离开动画
     * @return
     */
    public MyPostcard withTransition(int enterAnim, int exitAnim) {
        postcard.withTransition(enterAnim, exitAnim);
        return this;
    }

    public MyPostcard addFlags(int flags) {
        postcard.addFlags(flags);
        return this;
    }

    /**
     * 页面跳转
     *
     * @return
     */
    public Object navigation() {
        return postcard.navigation();
    }

    /**
     * 页面跳转
     *
     * @param context
     * @return
     */
    public Object navigation(Context context) {
        return postcard.navigation(context);

    }

    /**
     * 页面跳转 在Activity.onActivityResult(int, int, Intent)中监听回掉
     *
     * @param activity
     * @param requestCode 必须大于0
     * @return
     */
    public void navigation(Activity activity, int requestCode) {
        postcard.navigation(activity, requestCode);
    }


}
